import { defineStore } from 'pinia';
import storage from '@/utils/storage';

export const useUserStore = defineStore( 'user', {
  state: () => {
    return {
      token: storage.get( 'token' ) || '',
      user: storage.get( 'user' ) || {},
      expireTime: storage.get( 'expire_in' ) || 7200,
      name: '13131313',
      time: '',
      roles: [],
      permissions: []
    }
  },
  actions: {
    SET_TOKEN( data ) {
      this.token = data
      storage.set( 'token', data );
    },
    SET_USER( data ) {
      this.user = data
      storage.set( 'user', data );
    },
    SET_EXPIRE_TIME( data ) {
      this.expireTime = data
      storage.set( 'expire_time', data );
    },
    SET_TIME( data ) {
      this.time = data
      storage.set( 'time', data );
    }
  }
})
